<!--
 * @Author: your name
 * @Date: 2020-11-24 16:40:23
 * @LastEditTime: 2020-12-18 17:30:07
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solax-design\src\views\projectList\addprojectList.vue
-->
<template>
    <div class="addProjectList-main-box">
        <!-- 
            next 为当前栏的下一栏是否开启
            active 为当前栏的id
            menus 为数据
            all 修改的时候用，全部打开
            changeClick 为点击事件的回调钩子
         -->
        <div>
            <steps :next='next' v-model="active" :menus='menus' :all='all' @changeClick='changeClick'></steps>
        </div>
        <el-divider content-position="left"></el-divider>
        <div class="tabs-content-box">
            <div v-show='active==1'>
                <projectData @closeAll='closeAll' :azimuth="azimuth" :form="projectFormData" :po-form-data="poFormData" :active='active' @noticeUpload='noticeUpload'></projectData>
            </div>
            <div v-show='active==2'>
                <moduleData @closeAll='closeAll' :azimuth="azimuth" :data="moduleFormData" :isEdit="true" :po-form-data="poFormData" :cityId="cityId" @noticeUpload='noticeUpload' @PoFormUpload='PoFormUpload'></moduleData>
            </div>
            <div v-show='active==3'>
                <inverterData :form="inverterFormData" :po-form-data="poFormData" @noticeUpload='noticeUpload' :active='active'></inverterData>
            </div>
            <div v-show='active==4'>
                <cableData :form="cableFormData" :considerAcCableLosses='considerAcCableLosses'
                :considerDcCableLosses='considerDcCableLosses'  :po-form-data="poFormData" @noticeUpload='noticeUpload'></cableData>
            </div>
            <div v-show='active==5'>
                <returnData :form="returnFormData" :po-form-data="poFormData" :active='active'></returnData>
            </div>
            <div v-show='active==6'>
                <resultData :data="resultFormData" :po-form-data="poFormData"></resultData>
            </div>
        </div>
    </div>
</template>

<script>
import steps from './steps'
import projectData from './projectData'
import moduleData from './moduleData'
import inverterData from './inverterData/inverterData'
import cableData from './cableData'
import returnData from './returnData'
import resultData from './resultData'
export default {
    components: {
        steps,
        projectData,
        moduleData,
        inverterData,
        cableData,
        resultData,
        returnData
    },
    props: {

    },
    data() {
        return {

            azimuth:{
                azimuthProposal:0,
                inclinationProposal:30
            },

            proId:this.$route.query.id,
            data:{},
            cityId:'',
            /*项目数据*/
            projectFormData:{},
            /*光伏模块*/
            moduleFormData:{forms:[{}]},
            /*逆变器*/
            inverterFormData:{},
            /*电缆配置*/
            cableFormData:[],
            /*投资回报*/
            returnFormData:{},
            /*结果概述*/
            resultFormData:{},
            /*项目概述模块数据*/
            poFormData:{},
            active:1,
            showFlag:false,
            next:false,
            all:true,
            menus:[{
                id:1,
                icon:'iconfont icon-xiangmu',
                text:this.$t('project.data'),
                next:true
            },{
                id:2,
                icon:'iconfont icon-mokuai',
                text:this.$t('project.data.PV-module'),
                next:false
            },{
                id:3,
                icon:'iconfont icon-nibianqi',
                text:this.$t('project.data.inverter'),
                next:false
            },{
                id:4,
                icon:'iconfont icon-dianlan',
                text:this.$t('project.data.cable-dimensioning'),
                next:false
            },{
                id:5,
                icon:'iconfont icon-touzi',
                text:this.$t('project.data.return-data'),
                next:false,
            },{
                id:6,
                icon:'iconfont icon-zongjie',
                text:this.$t('project.data.result-overview'),
                next:false,
            }],
            considerAcCableLosses:'',
            considerDcCableLosses:'',
        };
    },
    computed: {

    },
    watch: {
        active:{
            handler(nv,ov){
                this.$store.commit('setProjectActive',nv)
            },
        },
        poFormData:{
            handler(nv,ov){
                this.$store.commit('setPoFormData',nv)
            }
        }
    },
    created() {

    },
    mounted() {
        // this.wifiEditEntity()
        if(this.proId){
            this.getProjectDetail()
        }
    },
    methods: {
        //刷新全部
        noticeUpload(res){
            this.newAssembleDetail(res)
        },
        //刷新右侧
        PoFormUpload(res){
            this.assemblePoFormData(res);
            this.assembleInverterData(res)
        },
        /*获取项目详情数据*/
        async getProjectDetail(){
            let res = await this.API.projectDetailGetById({
                projectId: this.proId
            })
            this.assembleDetail(res)
        },
        closeAll(flag){
            this.all = flag
        },
        
        /*组装电缆配置数据*/
        assembleCableFormData(res){
            this.cableFormData = res.cableLossInfos
            this.considerAcCableLosses = res.considerAcCableLosses
            this.considerDcCableLosses = res.considerDcCableLosses
        },
        /*投资回报*/
        assembleReturnFormData(res){
            this.returnFormData=res.tReturnInvestment
            this.returnFormData.proId=this.proId
        },
        /*结果概述*/
        assembleResultFormData(res){
            if(res && res.po){
                let invData=[]
                let proObj={}
                proObj.invName=res.projectInfo.proName
                proObj.peakPower=res.po.totalPeakPower
                proObj.moduleCount=res.po.totalModuleCount
                proObj.inverterNum=res.po.totalInvCount
                proObj.pinvAcnom=res.po.totalPAcnom
                proObj.ioAnnualEnergy=res.po.annualEnergy
                proObj.ioLineLoss=res.po.totalLineLosses
                proObj.statusImg=null

                invData.push(proObj)
                for(let key in res.iorMap){
                    invData.push(res.iorMap[key])
                }
                let obj={
                    proData:proObj,
                    invData:invData,
                    proName:res.proName
                }
                this.resultFormData=obj
            }
        },
        /*组装详情数据*/
        assembleDetail(res){
            let data = res.object
            this.azimuth.azimuthProposal = data.azimuthProposal
            this.azimuth.inclinationProposal = data.inclinationProposal
            this.assembleProjectFormData(data)
            this.assembleModuleFormData(data)
            this.assemblePoFormData(data);
            this.assembleInverterData(data)
            this.assembleReturnFormData(data)
            this.assembleResultFormData(data)

            this.assembleCableFormData(data)
        },
         newAssembleDetail(res){
            let data = res
            this.assembleProjectFormData(data)
            this.assembleModuleFormData(data)
            this.assemblePoFormData(data);
            this.assembleInverterData(data)
            this.assembleCableFormData(data)
            this.assembleResultFormData(data)
        },

        /*组装光伏模块数据*/
        assembleModuleFormData(res){
            if(res && res.projectInfo){
                this.cityId=res.projectInfo.cityId
            }
            let data = []
            if(res.pvArrays){
                res.pvArrays.forEach((item,index)=>{
                    if(item){
                        let pv = {
                            name: item.name||  this.$t("new.PV.management.PV-array")+'-'+(index+1),
                            manufacturerId: item.manufacturerId||'',
                            moduleId: item.moduleId||'',
                            moduleCount: item.moduleCount,
                            inclination: item.inclination ,
                            proposalIncli: item.proposalIncli,
                            azimuth: item.azimuth ,
                            proposalAzimuth: item.proposalAzimuth,
                            usedModuleCount: item.usedModuleCount,
                            peakPower: item.peakPower,//默认单位kWp,需要除1000
                            originPearPower:item.peakPower,
                            selectLable:1,
                            select: 1 ,//默认单位kWp
                            pModMPP:item.pModMPP, // 额定功率
                        }
                        if(pv.proposalIncli){
                            pv.inclination = this.azimuth.inclinationProposal
                        }
                        if(pv.proposalAzimuth){
                            pv.azimuth = this.azimuth.azimuthProposal
                        }
                        this.changeMoudleSelect(pv)
                        data.push(pv)
                    }
                })
            }
            this.moduleFormData.forms = data
        },

        /*计算光伏模块峰值功率单位*/
        changeMoudleSelect(item){
            if(item.peakPower > 1000*1000){
                item.select = 3
                item.peakPower = item.peakPower/1000000
            }else if(item.peakPower > 1000 ){
                item.select = 2
                item.peakPower = item.peakPower/1000
            }else {
                item.select = 1
            }
        },


        /*组装项目模块数据*/
        assembleProjectFormData(obj){
            obj = obj.projectInfo
            if(obj){
                let data = {
                    countryId: obj.countryId ? parseInt(obj.countryId) : '',
                    cityId: obj.cityId ?  parseInt(obj.cityId): '',
                    regionId: parseInt(obj.regionId)== null ? '':parseInt(obj.regionId) ,
                    proName: obj.proName== null ? '':(obj.proName) ,
                    proNumber: obj.proNumber== null ? '':(obj.proNumber) ,
                    clientName: obj.clientName== null ? '':(obj.clientName) ,
                    tempMode: obj.tempMode == null ? '':(obj.tempMode) ,
                    cellLowTemp: obj.cellLowTemp== null ? '':(obj.cellLowTemp) ,
                    cellAverageTemp: obj.cellAverageTemp== null ? '':(obj.cellAverageTemp) ,
                    cellHighTemp: obj.cellHighTemp== null ? '':(obj.cellHighTemp) ,
                    ambientLowTemp: obj.ambientLowTemp== null ? '':(obj.ambientLowTemp) ,
                    ambientAverageTemp: obj.ambientAverageTemp== null ? '':(obj.ambientAverageTemp) ,
                    ambientHighTemp: obj.ambientHighTemp== null ? '':(obj.ambientHighTemp) ,
                    gridId: obj.gridId == null ? '':obj.gridId ,
                    comment: obj.comment,
                    demandsPowerFactor: obj.demandsPowerFactor== null ? '':(obj.demandsPowerFactor) ,
                    displacementPowerFactor: obj.displacementPowerFactor== null ? '':(obj.displacementPowerFactor)
                }
                data.factorfPre =
                    (data.displacementPowerFactor && data.displacementPowerFactor > 0) ? 1:-1
                if(data.displacementPowerFactor){
                    data.displacementPowerFactor = Math.abs(obj.displacementPowerFactor);
                }
                this.projectFormData = data;
            }
        },


        /*组装项目概述数据*/
        assemblePoFormData(obj){
            if(obj && obj.po){
                let po = obj.po
                let data = {
                    totalModuleCount: po.totalModuleCount,
                    totalPeakPower: po.totalPeakPower,
                    totalInvCount: po.totalInvCount,
                    totalPAcnom: po.totalPAcnom,
                    annualEnergy: po.annualEnergy,
                    dcCableLength: po.dcCableLength,
                    dcPowerLossNom: po.dcPowerLossNom,
                    dcRelPowerLossNom: po.dcRelPowerLossNom,
                    acCableLength: po.acCableLength,
                    acPowerLossNom: po.acPowerLossNom,
                    acRelPowerLossNom: po.acRelPowerLossNom,
                    totalCableLength: po.totalCableLength,
                    totalPowerLossNom: po.totalPowerLossNom,
                    totalPowerLoss: po.totalPowerLoss,
                    lineLosses: po.lineLosses,
                    nomPowerFrom:obj.projectInfo.nomPowerFrom,
                    nomPowerTo:obj.projectInfo.nomPowerTo,
                    dcRelPowerLossImageStatus:obj.po.dcRelPowerLossImageStatus,
                    acRelPowerLossImageStatus:obj.po.acRelPowerLossImageStatus,
                    totalPowerLossImageStatus:obj.po.totalPowerLossImageStatus,
                }
                this.poFormData = data
            }
        },


        /*组装逆变器数据*/
        assembleInverterData(obj){
            if(obj && obj.iorMap){
                let arr = [];
                Object.keys(obj.iorMap).forEach(item=>{
                    obj.iorMap[item]['invSequence'] = item
                    arr.push(obj.iorMap[item])
                })
                // this.inverterFormData.forms = arr
                this.$set(this.inverterFormData,'forms',arr)
                this.inverterFormData.pvArrays = []
                let i = 0
                obj.pvArrays.forEach(item=>{
                    if(item){
                        item['id'] = i
                        // this.inverterFormData.pvArrays.push(item)
                        this.$set(this.inverterFormData.pvArrays,i,item)
                    }
                    i++
                })
                // this.$emit('setpvArraysInv',this.inverterFormData.pvArrays)
                this.$store.commit('setpvArraysInv',this.inverterFormData.pvArrays)
            }
        },


        /*组装电缆配置数据*/



        cs(){
            this.next = !this.next
        },



        changeClick(item){
            if(item.id == 2){
                // 加载光伏模块数据
            }else if(item.id == 3){
                // 加载逆变器数据
            }else if(item.id == 4){
                // 加载电缆配置数据
            }else if(item.id == 6){
                // 结果概述
            }
            // console.log(item,'item');
            // this.next = false
        },

    },
};
</script>

<style  lang="less">
.addProjectList-main-box{
    min-width: 1260px;
    .steps-box{
        width: 80%;
        margin: 0 auto;
        
        .next{
            .iconfont{
                color: #FFAF40;
            }
            .el-step__title.is-wait{
                color: #FFAF40;
                border-color:#FFAF40;
            }
        }
        .el-steps--simple{
            background-color: #fff;
        }
    }
    .tabs-content-box{
         margin-top: 20px;
    }
    .el-card{
        overflow: inherit;
    }
    .el-card__header {
        padding: 8px 10px;
        background: #f5f5f5;
    }
    .el-card .box-card .is-always-shadow{
        transition: all .3s ease;
    }
    .el-card:hover {
        // transform: scale(1.015);
        // transform: translate3d(-10px,-5px,0px);
        // box-shadow: 10px 10px 20px 0px rgba(3, 81, 155, 0.3);
    }
}
</style>
